package org.me.SendSMS;

import org.me.SendSMS.utli.GlobalVariable;

import com.google.android.apps.analytics.GoogleAnalyticsTracker;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class SelectTimeLoopActivity extends Activity implements OnClickListener{
	
	Context mContext;
	String hoursloop	="0";
	String minuteloop 	= "0";
	Button btnSetLoop,btnCancelLoop;
	Button btnCongHoursLoop, btnTruHoursLoop,btnCongMinuteLoop,btnTruMinuteLoop;
	EditText editHoursLoop,editMinuteLoop;
	private GoogleAnalyticsTracker tracker;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_LEFT_ICON);
		 tracker = GoogleAnalyticsTracker.getInstance();
	     // Start the tracker in manual dispatch mode...
	    tracker.startNewSession("UA-35081259-1", getApplication());
		setContentView(R.layout.set_time_loop);
		getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon_time);
		


		mContext = this;
		
		editHoursLoop		= (EditText)findViewById(R.id.editHourLoop);
		editMinuteLoop		= (EditText)findViewById(R.id.editMinuteLoop);
		
		
		
		if(GlobalVariable.HOURS_CURRENT_LOOP<10)
		{
			hoursloop = "0"+String.valueOf(GlobalVariable.HOURS_CURRENT_LOOP);
		}
		else
		{
			hoursloop = String.valueOf(GlobalVariable.HOURS_CURRENT_LOOP);
		}
		if(GlobalVariable.MINUTE_CURRENT_LOOP<10)
		{
			minuteloop = "0"+String.valueOf(GlobalVariable.MINUTE_CURRENT_LOOP);
		}
		else
		{
			minuteloop = String.valueOf(GlobalVariable.MINUTE_CURRENT_LOOP);
		}
		
		
		
		
		
		editHoursLoop.setText(hoursloop);
		editMinuteLoop.setText(minuteloop);
		
		btnSetLoop 			= (Button)findViewById(R.id.SetLoop);
		btnCancelLoop		= (Button)findViewById(R.id.CancelLoop);
		
		btnCongHoursLoop	= (Button)findViewById(R.id.btnCongHoursLoop);
		btnTruHoursLoop		= (Button)findViewById(R.id.btnTruHoursLoop);
		
		btnCongMinuteLoop	= (Button)findViewById(R.id.btnCongMinuteLoop);
		btnTruMinuteLoop	= (Button)findViewById(R.id.btnTruMinuteLoop);
		
		btnSetLoop.setOnClickListener(this);
		btnCancelLoop.setOnClickListener(this);
		
		btnCongHoursLoop.setOnClickListener(this);
		btnTruHoursLoop.setOnClickListener(this);
		
		btnCongMinuteLoop.setOnClickListener(this);
		btnTruMinuteLoop.setOnClickListener(this);
		
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
		switch (v.getId()) {
		case R.id.CancelLoop:
			
			finish();
			break;
		case R.id.btnCongHoursLoop:
			GlobalVariable.HOURS_CURRENT_LOOP = Integer.parseInt(editHoursLoop.getText().toString());
			GlobalVariable.HOURS_CURRENT_LOOP ++;
			
			if(GlobalVariable.HOURS_CURRENT_LOOP>23)
			{
				GlobalVariable.HOURS_CURRENT_LOOP = 0;
			}
			if(GlobalVariable.HOURS_CURRENT_LOOP<10)
			{
				editHoursLoop.setText("0" + String.valueOf(GlobalVariable.HOURS_CURRENT_LOOP));
			}
			else
			{
				editHoursLoop.setText(String.valueOf(GlobalVariable.HOURS_CURRENT_LOOP));
			}
			break;
		case R.id.btnTruHoursLoop:
			GlobalVariable.HOURS_CURRENT_LOOP = Integer.parseInt(editHoursLoop.getText().toString());
			GlobalVariable.HOURS_CURRENT_LOOP --;
			if(GlobalVariable.HOURS_CURRENT_LOOP<=0)
			{
				GlobalVariable.HOURS_CURRENT_LOOP = 24;
			}
			if(GlobalVariable.HOURS_CURRENT_LOOP<10)
			{
				editHoursLoop.setText("0" + String.valueOf(GlobalVariable.HOURS_CURRENT_LOOP));
			}
			else
			{
				editHoursLoop.setText(String.valueOf(GlobalVariable.HOURS_CURRENT_LOOP));
			}
			break;
		case R.id.btnCongMinuteLoop:
			GlobalVariable.MINUTE_CURRENT_LOOP = Integer.parseInt(editMinuteLoop.getText().toString());
			
			GlobalVariable.MINUTE_CURRENT_LOOP ++;
			if(GlobalVariable.MINUTE_CURRENT_LOOP>59)
			{
				GlobalVariable.MINUTE_CURRENT_LOOP = 0;
			}
			
			if(GlobalVariable.MINUTE_CURRENT_LOOP<10)
			{
				editMinuteLoop.setText("0" + String.valueOf(GlobalVariable.MINUTE_CURRENT_LOOP));
			}
			else
			{
				editMinuteLoop.setText(String.valueOf(GlobalVariable.MINUTE_CURRENT_LOOP));
			}
			
			break;
		case R.id.btnTruMinuteLoop:
			GlobalVariable.MINUTE_CURRENT_LOOP = Integer.parseInt(editMinuteLoop.getText().toString());
			GlobalVariable.MINUTE_CURRENT_LOOP --;
			if(GlobalVariable.MINUTE_CURRENT_LOOP<=0)
			{
				GlobalVariable.MINUTE_CURRENT_LOOP = 59;
			}
			if(GlobalVariable.MINUTE_CURRENT_LOOP<10)
			{
				editMinuteLoop.setText("0" + String.valueOf(GlobalVariable.MINUTE_CURRENT_LOOP));
			}
			else
			{
				editMinuteLoop.setText(String.valueOf(GlobalVariable.MINUTE_CURRENT_LOOP));
			}
			break;
		case R.id.SetLoop:
			GlobalVariable.HOURS_LOOP = Integer.parseInt(editHoursLoop.getText().toString());
			GlobalVariable.MINUTE_LOOP = Integer.parseInt(editMinuteLoop.getText().toString());
			GlobalVariable.STARTTIMELOOP = true;
			finish();
			break;
			


		default:
			break;
		}
		
	}

}
